#include <iostream>
#include <type_traits>

class Drawable {
public:
    Drawable() = default;
    void draw() const { std::cout << "Drawing..." << std::endl; }
};

class Clickable {
public:
    Clickable() = default;
    void click() const { std::cout << "Clickable!" << std::endl; }
};

class Hoverable {
public:
    Hoverable() = default;
    void hover() const { std::cout << "Hover effect!" << std::endl; }
};

template<typename T, typename = void>
struct has_draw : std::false_type {};

template<typename T>
struct has_draw<T, std::void_t<decltype(std::declval<T>().draw())>> : std::true_type {};

template<typename ExtraType, typename... Mixins>
class Widget : public Mixins... {
public:
    ExtraType extraData;

    // 委托构造函数，适用于不提供 Mixins 的情况
    Widget(const ExtraType& data) : Widget(data, Mixins()...) {}

    // 主构造函数
    Widget(const ExtraType& data, const Mixins&... mixins)
    : Mixins(mixins)..., extraData(data) {}

    template<typename T>
    void tryDraw() const {
        if constexpr (has_draw<T>::value) {
            static_cast<const T*>(this)->draw();
        }
    }

    void draw() const {
        (..., tryDraw<Mixins>());
    }
};

int main() {
    Widget<int, Drawable, Clickable, Hoverable> widget(42);
    widget.draw();
    widget.click();
    widget.hover();
    std::cout << "Extra data: " << widget.extraData << std::endl;
    return 0;
}